package com.waimai.app.qa.tool;

import java.io.File;
import java.util.Map;

/**
 * ClassGeneratorHelper Class
 * @author AiHui
 */
public class ClassGeneratorHelper{

	public static IOProcessor ioproc = new IOProcessor();
	public static PagesGenerator mg=new PagesGenerator();
	public static final String fs= File.separator;

	public ClassGeneratorHelper(){
	
	}
	
    /**
     * 
     * @param inFileName
     * @return
     */
	public static Map getVarsName(String inFileName){
		return ioproc.readNameFromFile(inFileName);
	}
	
    /**
     *将文本的内容读入到输出文件中
     * @param text
     * @param outFileName
     */
	public static void writeToFile(String text, String outFileName){
		ioproc.writeToFile(text, outFileName);
	}
	
    /**
     * 将inDir文件夹中的csv文件读入，经过处理后形成.java文件并输出到outDir中
     * @param inDir
     * @param outDir
     */
	public void  generatePageClasses(String inDir,String outModules){   
		
		String as[] = ioproc.listFilesName(inDir);
		int j = as.length;
		for (int i = 0; i < j; i++)
		{
			String fileName = as[i];
			Map<String,String>  varsName = (Map) getVarsName((new StringBuilder(String.valueOf(inDir))).append(fs).append(fileName).toString());
			
			String name = fileName.replace(".csv", "");
			System.out.println((new StringBuilder("Processing: ")).append(inDir).append(fs).append(fileName).toString());
			writeToFile(mg.generatePageClass(varsName,name), (new StringBuilder(String.valueOf(outModules))).append(fs).append(name).append(".java").toString());
		}
	}
}
